<?php
/// http://192.168.18.23/master/mcGM/tmp_process/sendNoticeInfo.php
$memcachehost = '127.0.0.1';
$memcacheport = 11211;
$memcachelife = 120;
$memcache = new Memcache;
$memcache->connect($memcachehost,$memcacheport) or die ("Could not connect");
$query="SELECT * FROM tt_notice";
$key=md5($query);

if(!$memcache->get($key))
{
	$tmp_notic_array = array(); 
	$conn=mysql_connect("127.0.0.1","teamtop","teamtop136");
	mysql_select_db("shouhuzhemen_gm");
	$result_db=mysql_query($query);
	while ($row=mysql_fetch_assoc($result_db))
	{
		$arr[]=$row;
	}

	$f = 'mysql';
	$memcache->add($key,serialize($arr),0,$memcachelife);        //mysql 查询后，插入 memcached
	$data = $arr ;
}
else
{
	$f = 'memcache';
	$data_mem=$memcache->get($key);
	$data = unserialize($data_mem);
}

foreach($data as $rowdata)
{
	$rowdata['content']=str_replace('"', ' ', $rowdata['content']);

	//是否显示"新"字,为1表示显示
	strtotime($rowdata['inserttime']) + $rowdata['timesec'] > time() ? $rowdata['flag'] = 1 : $rowdata['flag'] = 0;

	if ($rowdata['type'] == 1){
		$tmp_notic_array[$rowdata['tmpsequence']] = array(
							'name' => urlencode($rowdata['name']),
							'flag' => urlencode($rowdata['flag']),
							'title' => urlencode($rowdata['title']),
							'content' => urlencode($rowdata['content'])
					);
	}
	else
	{
		$rowdatalist2 = array(
				'name' => urlencode($rowdata['name']),
				'flag' => urlencode($rowdata['flag']),
				'title' => urlencode($rowdata['title']),
				'content' => urlencode($rowdata['content'])
		);	
	}
}
/*
echo $f;
echo "<br>";

print_r($data);
echo "<br>";
print_r($tmp_notic_array);
*/
ksort($tmp_notic_array);
foreach ($tmp_notic_array as $k=>$v){
	$notic_array[] = $v;
}
//echo "<br>++++<br>";
//print_r($notic_array);
//exit(0);
$result = array();
$result["close"] = isset($rowdatalist2);
if(!$result["close"])
{
	$result["notics"] = $notic_array;
}
else
{
	$result["notics"] = array();
	$result["notics"][] = $rowdatalist2;
}
echo urldecode(json_encode($result));

?>
